define (require, exports, module) ->
  # 引入样式
  require 'mods/rczp_detail/rczp_detail_css.css'
  # 引入API服务
  rczp_detail_api = require 'mods/rczp_detail/rczp_detail_api'

  module.exports = Vue.extend

    # 组件模板
    template: require 'mods/rczp_detail/rczp_detail_tpl.js'

    # 定义变量
    data: () ->
      # 是否加载完成
      loadedSucc: false
      # 加载失败提示语
      loadedFail: ''
      # 热门招聘职位列表
      hot_list: []
      # 人才招聘详情
      rczp_xq: []
      # 区别当前招聘详情页和热门职位详情页
      isShow: true
      # 热门职位详情
      hot_xq: []

    # 定义方法
    methods:

      # 插件加载
      pluginLoad: () ->
        self = @

      # 加载成功
      loadedSuccFunc: () ->
        self = @
        self.$nextTick () ->
          # 获取人才招聘详情
          self.getRczpDetail()
          # 获取热门人才招聘详情
          self.getRczpList()
          # 加载成功标识
          self.loadedSucc = true
          # 插件加载
          self.pluginLoad()

      # 日期格式转换 YY-MM-DD
      changeDate: (dateStr) ->
        tmp_year = dateStr.substring 0, 4
        tmp_month = dateStr.substring 4, dateStr.length - 2
        tmp_day = dateStr.substring dateStr.length - 2
        tmpDate = tmp_year + tmp_month + tmp_day
        # tmpDate = tmp_year + "-" + tmp_month + "-" + tmp_day
        return tmpDate

      # 人才招聘详情页跳转
      toggleHref: (_id) ->
        self = @
        self.isShow = false

        currPath = '/rczp_detail/' + _id
        self.$router.push currPath
        # 查询热门职位详情参数
        params =
          rczp_id: _id

        return rczp_detail_api.getRczpDetail params
          .then (res) ->
            self.hot_xq = res?.body
          .catch (err) ->
            console.log err

      # 获取人才招聘详情
      getRczpDetail: () ->
        self = @
        tmpid =  window.location.href
        id = tmpid.substr tmpid.length - 24
        # 查询人才招聘详情参数
        params =
          rczp_id: id

        return rczp_detail_api.getRczpDetail params
          .then (res) ->
            self.rczp_xq = res?.body
          .catch (err) ->
            console.log err

      # 获取热门人才招聘列表
      getRczpList: () ->
        self = @

        # 查询热门人才招聘列表参数
        params =
          pageNum: 1
          pageSize: 10

        return rczp_detail_api.getRczpList params
          .then (res) ->
            self.hot_list = res?.body?.data

          .catch (err) ->
            console.log err

    # 计算属性
    computed:

      # 加载中的样式
      loaddingClass: () ->
        self = @
        if self.loadedSucc
          return 'c-hidden'
        if self.loadedFail
          return 'c-hidden'
        return ''

      # 加载成功的样式
      loadedSuccClass: () ->
        self = @
        return if self.loadedSucc then '' else 'c-vhidden'

      # 加载失败的样式
      loadedFailClass: () ->
        self = @
        return if self.loadedFail then '' else 'c-hidden'

    # 组件初始化执行
    mounted: () ->
      self = @
      # 加载成功 - 处理函数
      return self.loadedSuccFunc()